#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int N;
int vis[64] = {0};
int len;

bool dfs(vector<int>& nums, int pos, int curlen, int cnt)
{
    if(cnt == 0) 
        return true;
    if(len == curlen) 
        return dfs(nums, 0, 0, cnt-1);
    for(int i=pos;i<N;i++)
    {
        if(!vis[i] && curlen + nums[i] <= len)
        {
            vis[i] = 1;
            if(dfs(nums, pos+1, curlen + nums[i], cnt))
                return true;
            vis[i] = 0;
            if(curlen == 0) return false; // sticks left are impossible
            while(i + 1 < N && nums[i+1] == nums[i])
                ++i;
        }
    }
    return false;
}

int main()
{

    while (scanf("%d",&N),N)
    {
        vector<int>nums(N);
        int sum = 0;
        for(int i=0;i<N;i++)
        {
            cin >> nums[i];
            sum += nums[i];
        }

        sort(nums.begin(),nums.end(), [](const int& a, const int& b){return a > b;});
        //early end if start from biggest
        for(int i=nums[0];i<=sum;i++)
        {
            if(sum % i == 0)
            {
                len = i;
                memset(vis, 0, sizeof(vis));
                if(dfs(nums, 0, 0, sum / i))
                {
                    cout << len <<endl;
                    break;
                }
            }
        }
    }
    return 0;
}